package th.go.drr.gps.domain;

import javax.persistence.CascadeType;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Id;
import javax.persistence.Column;
import javax.persistence.TableGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.JoinColumn;

import java.util.Calendar;
import java.util.HashSet;
import java.util.Set;

@Entity
@Table(name = "usr")
public class Usr implements java.io.Serializable {
	private static final long serialVersionUID = 1L;

	@GeneratedValue(generator = "USR_SEQ", strategy = GenerationType.TABLE)
	@Id
	@TableGenerator(name = "USR_SEQ", table = "sequence", allocationSize = 1)
	private Long id;

	@Column(name = "create_by", nullable = false)
	private Long createBy;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "create_date", nullable = false)
	private Calendar createDate;

	@Column(name = "passwd", nullable = false, length = 63)
	private String passwd;

	@Column(name = "update_by", nullable = false)
	private Long updateBy;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "update_date", nullable = false)
	private Calendar updateDate;

	@Column(name = "username", length = 63,unique = true)
	private String username;

	@Column(name = "account_expired")
	private Boolean accountExpired;

	@Column(name = "account_locked")
	private Boolean accountLocked;

	@Column(name = "credentials_expired")
	private Boolean credentialsExpired;

	@Column(name = "enable")
	private Boolean enable;

	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Calendar getCreateDate() {
		return this.createDate;
	}

	public void setCreateDate(Calendar createDate) {
		this.createDate = createDate;
	}

	public String getPasswd() {
		return this.passwd;
	}

	public void setPasswd(String passwd) {
		this.passwd = passwd;
	}

	public Calendar getUpdateDate() {
		return this.updateDate;
	}

	public void setUpdateDate(Calendar updateDate) {
		this.updateDate = updateDate;
	}

	public Long getCreateBy() {
		return createBy;
	}

	public void setCreateBy(Long createBy) {
		this.createBy = createBy;
	}

	public Long getUpdateBy() {
		return updateBy;
	}

	public void setUpdateBy(Long updateBy) {
		this.updateBy = updateBy;
	}

	public void setEnable(Boolean enable) {
		this.enable = enable;
	}

	public String getUsername() {
		return this.username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	@ElementCollection
	private Set<Authority> authorities = new HashSet<Authority>(0);

	@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, targetEntity = Authority.class)
	@JoinTable( name = "usr_authorities", joinColumns = { @JoinColumn(name = "id", referencedColumnName="usr_id")  }
	, inverseJoinColumns = { @JoinColumn(name = "authorities_id",referencedColumnName ="id") }
	)
	// @LazyCollection(LazyCollectionOption.EXTRA)
	public Set<Authority> getAuthorities() {
		return authorities;
	}

	public void setAuthorities(Set<Authority> authorities) {
		this.authorities = authorities;
	}

	public Boolean getAccountExpired() {
		return accountExpired;
	}

	public void setAccountExpired(Boolean accountExpired) {
		this.accountExpired = accountExpired;
	}

	public Boolean getAccountLocked() {
		return accountLocked;
	}

	public void setAccountLocked(Boolean accountLocked) {
		this.accountLocked = accountLocked;
	}

	public Boolean getCredentialsExpired() {
		return credentialsExpired;
	}

	public void setCredentialsExpired(Boolean credentialsExpired) {
		this.credentialsExpired = credentialsExpired;
	}

	public Boolean getEnable() {
		return enable;
	}

	public void setEnabled(Boolean enable) {
		this.enable = enable;
	}
}